home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / sgopher0.3 / shar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-10  |  1.2 KB  |  58 lines

  1. /*
  2.         shar.c - a very simple shell archiver
  3.  
  4.         author      : Sean Fuller (fuller@aedc-vax.af.mil)
  5.                       Arnold Engineering and Development Center
  6.  
  7.         This software is provided "as is" without express or
  8.         implied warranty.  In no event shall the author be liable
  9.         for damages of any kind arising from or in connection
  10.         with the use of this software.
  11.  
  12. */
  13.  
  14. #include <stdio.h>
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18.     int i;
  19.     FILE *fp;
  20.     char buf[256];
  21.     fp = fopen("README", "r");
  22.     if (fp == NULL)
  23.     {
  24.         fprintf(stderr, "Error: cannot open README\n");
  25.         return 1;
  26.     }
  27.     while (!feof(fp))
  28.     {
  29.         if (fgets(buf, 256, fp) == NULL) break;
  30.         printf("%s", buf);
  31.     }
  32.     fclose(fp);
  33.     printf("#!/bin/sh\n");
  34.     printf("# This is a shell archive.\n");
  35.     for (i=1; i<argc; i++)
  36.     {
  37.         fp = fopen(argv[i], "r");
  38.         if (fp == NULL)
  39.         {
  40.             fprintf(stderr, "Error: cannot open %s\n", argv[i]);
  41.             return 1;
  42.         }
  43.         printf("echo unpacking %s...\n", argv[i]);
  44.         printf("sed \"s/^X//\" >'%s' <<'END_OF_FILE'\n", argv[i]);
  45.         while (!feof(fp))
  46.         {
  47.             if (fgets(buf, 256, fp) == NULL) break;
  48.             printf("X%s", buf);
  49.         }
  50.         fclose(fp);
  51.         printf("END_OF_FILE\n");
  52.     }
  53.     printf("echo done.\n");
  54.     printf("exit 0\n");
  55.     return 0;
  56. }
  57.  
  58.